package com.own.business.exam.entity.dto;

import com.own.business.exam.entity.bo.ExamBo;
import com.own.component.common.base.entity.BaseDto;
import com.own.component.common.util.DateUtil;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * ExamDto
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/05/18 14:24:25
 * @since 4.0.0
 */
@ApiModel("考试表" + ConstantBeanSuffix.DTO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ExamDto extends BaseDto<ExamBo> {

    @ApiModelProperty("考试标题")
    @NotBlank(message = "请输入考试标题信息")
    @Length(max = 50, message = "考试标题长度不能超过50个字符")
    private String title;

    @ApiModelProperty("开始时间")
    @DateTimeFormat(pattern = DateUtil.Pattern.DATETIME)
    @NotNull(message = "请选择考试开始时间")
    private LocalDateTime startTime;

    @ApiModelProperty("结束时间")
    @DateTimeFormat(pattern = DateUtil.Pattern.DATETIME)
    @NotNull(message = "请选择考试结束时间")
    private LocalDateTime endTime;

    @ApiModelProperty("满分分数")
    @Min(value = 0, message = "满分分数最小为0")
    @Max(value = 1000, message = "满分分数最大为1000")
    private BigDecimal fullScore;

    @ApiModelProperty("是否指定人数 1=指定 0=不指定")
    private Integer isAssignNumber;

    @ApiModelProperty("考试最多容纳的人数 0表示不做限制")
    private Integer assignNumber;

    @ApiModelProperty("是否可以重复作答 1=可以 0=不可以")
    private Integer isRepeat;

    @ApiModelProperty("是否需要自定义分数 1=需要 0=不需要")
    private Integer isCustomerRank;

    @ApiModelProperty("是否直接判题验卷 1=是 0=不是")
    private Integer isDirectJudge;

    @ApiModelProperty("考试时间结束之后是否可以交卷 1=可以 0=不可以")
    private Integer isHandPaperAfterTime;

    @ApiModelProperty("考生查看考试答案的时机 1=交卷之后 2=指定时间 3=无法查看")
    private Integer viewAnswerType;

    @ApiModelProperty("查看试卷答案的时间")
    @DateTimeFormat(pattern = DateUtil.Pattern.DATETIME)
    private LocalDateTime viewAnswerTime;

    @ApiModelProperty("考试类型 1=普通考试 2=实名考试 3=...")
    @NotNull(message = "请选择考试类型")
    private Integer type;

    /**
     * 转业务层对象
     *
     * @param entity 原业务层对象
     * @return 业务层对象
     */
    @Override
    public ExamBo toBo(ExamBo entity) {
        if (entity == null) {
            entity = new ExamBo();
        }
        entity.setTitle(title);
        entity.setStartTime(startTime);
        entity.setEndTime(endTime);
        entity.setFullScore(fullScore);
        entity.setIsAssignNumber(isAssignNumber);
        entity.setAssignNumber(assignNumber);
        entity.setIsRepeat(isRepeat);
        entity.setIsCustomerRank(isCustomerRank);
        entity.setIsDirectJudge(isDirectJudge);
        entity.setIsHandPaperAfterTime(isHandPaperAfterTime);
        entity.setViewAnswerType(viewAnswerType);
        entity.setViewAnswerTime(viewAnswerTime);
        entity.setType(type);
        return super.toBo(entity);
    }

}
